package com.example.democonfigserver.modules.config;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author wangbin
 */
public interface ConfigRepository extends JpaRepository<Config, Integer> {
    @Query(value = "select c from Config c where c.env.id=:envId",
            countQuery = "select count(c) from Config c where c.env.id=:envId")
    Page<Config> findPageByEnvId(Pageable pageable, @Param("envId") Integer envId);

    @Query("select c from Config c where c.env.id=:envId")
    List<Config> findAllByEnvId(@Param("envId") Integer envId);

    @Query("select c from Config c left join fetch c.propertyList p where c.id=:id")
    Config findByIdFetchProperty(@Param("id") Integer id);
}
